<!--
    Document   : editprofile bedrijf met pakket c
    Created on : 24-mei-2011, 08:45:23
    Author     : Shahram abdi
-->
<div id="tabs">
    <ul>
        <li><a href="#fragment-1"><span>profiel</span></a></li>
        <li><a href="#fragment-2"><span>stages</span></a></li>
        <li><a href="#fragment-3"><span>vacatures</span></a></li>
        <li><a href="#fragment-4"><span>medewerkers</span></a></li>
    </ul>
    <div id="fragment-1">
        <div id="profile">
            <?php
            require_once('../config/appvars.php');
            require_once('../config/config.php');

            // Make sure the user is logged in before going any further.
            if (!isset($_SESSION['user_id']) && $_SESSION['pakket'] == 'c') {
                echo '<p class="login">Please <a href="../index.php?p=home">log in</a> to access this page.</p>';
                exit();
            }
            if ($_SESSION['pakket'] == 'c') {
                // Connect to the database
                $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);

                $query = "SELECT relatienummer FROM werkgeverprofiel WHERE werkgeverID = '" . $_SESSION['user_id'] . "'";
                $data = mysqli_query($dbc, $query);
                $row = mysqli_fetch_array($data);

                if (isset($_POST['delete'])) {
                    $queryMedewerkers = "DELETE FROM medewerkers WHERE relatienummer = '" . $row['relatienummer'] . "'";
                    mysqli_query($dbc, $queryMedewerkers);

                    $queryvacatures = "DELETE FROM vacatures WHERE relatienummer = '" . $row['relatienummer'] . "'";
                    mysqli_query($dbc, $queryvacatures);

                    $querystage = "DELETE FROM stages WHERE relatienummer = '" . $row['relatienummer'] . "'";
                    mysqli_query($dbc, $querystage);

                    $query = "DELETE FROM werkgeverprofiel WHERE werkgeverID = '" . $_SESSION['user_id'] . "'";
                    mysqli_query($dbc, $query);
                    $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php?p=deleteprofile';
                    header('Location: ' . $home_url);
                    mysqli_close($dbc);
                    exit();
                }
                if (isset($_POST['deleteMedewerkers'])) {
                    $query = "DELETE FROM medewerkers WHERE relatienummer = '" . $row['relatienummer'] . "'";
                    mysqli_query($dbc, $query);
                }

                if (isset($_POST['deleteVacatures'])) {
                    $query = "DELETE FROM vacatures WHERE relatienummer = '" . $row['relatienummer'] . "'";
                    mysqli_query($dbc, $query);
                }

                if (isset($_POST['deleteStage'])) {
                    $query = "DELETE FROM stages WHERE relatienummer = '" . $row['relatienummer'] . "'";
                    mysqli_query($dbc, $query);
                }

                if (isset($_POST['submitMedewerkers'])) {
                    $medewerkernaam = mysqli_real_escape_string($dbc, trim($_POST['medewerkernaam']));
                    $medewerkerspecialist = mysqli_real_escape_string($dbc, trim($_POST['medewerkerspecialist']));
                    if ($row != NULL) {
                        $relatienummer = $row['relatienummer'];
                        $query = 'INSERT INTO medewerkers(relatienummer, medewerkernaam, medewerkerspecialist ) ' .
                                'VALUES ("' . $relatienummer . '","' . $medewerkernaam . '","' . $medewerkerspecialist . '")';
                        // execute the SQL query
                        mysqli_query($dbc, $query);
                    }
                }

                if (isset($_POST['submitVacatures'])) {
                    $vacaturetitel = mysqli_real_escape_string($dbc, trim($_POST['vacaturetitel']));
                    $vacaturplaats = mysqli_real_escape_string($dbc, trim($_POST['vacaturplaats']));
                    $vacatureniveau = mysqli_real_escape_string($dbc, trim($_POST['vacatureniveau']));
                    $uren = mysqli_real_escape_string($dbc, trim($_POST['uren']));
                    $vomschrijving = mysqli_real_escape_string($dbc, trim($_POST['vomschrijving']));

                    if ($row != NULL) {
                        $relatienummer = $row['relatienummer'];
                        $query = 'INSERT INTO vacatures(relatienummer, vacaturetitel, vacaturplaats, vacatureniveau, uren, vomschrijving ) ' .
                                'VALUES ("' . $relatienummer . '","' . $vacaturetitel . '","' . $vacaturplaats . '","' . $vacatureniveau . '","' . $uren . '","' . $vomschrijving . '")';
                        // execute the SQL query
                        mysqli_query($dbc, $query);
                    }
                }

                if (isset($_POST['submitstage'])) {
                    $stagetitel = mysqli_real_escape_string($dbc, trim($_POST['stagetitel']));
                    $stageplaats = mysqli_real_escape_string($dbc, trim($_POST['stageplaats']));
                    $stagetype = mysqli_real_escape_string($dbc, trim($_POST['stagetype']));
                    $sniveau = mysqli_real_escape_string($dbc, trim($_POST['stageniveau']));
                    $stageperiode = mysqli_real_escape_string($dbc, trim($_POST['stageperiode']));
                    $stagevergoeding = mysqli_real_escape_string($dbc, trim($_POST['stagevergoeding']));
                    $stagedatum = mysqli_real_escape_string($dbc, trim($_POST['stagedatum']));
                    $omschrijving = mysqli_real_escape_string($dbc, trim($_POST['omschrijving']));

                    if ($row != NULL) {
                        $relatienummer = $row['relatienummer'];
                        $query = 'INSERT INTO stages(stagetitel, stageplaats, stagetype, stageniveau, stageperiode, stagevergoeding, stagedatum, omschrijving, relatienummer ) ' .
                                'VALUES ("' . $stagetitel . '","' . $stageplaats . '","' . $stagetype . '","' . $sniveau . '","' . $stageperiode . '","' . $stagevergoeding . '","' . $stagedatum . '","' . $omschrijving . '","' . $relatienummer . '")';
                        // execute the SQL query
                        mysqli_query($dbc, $query);
                    }
                }

                if (isset($_POST['submit'])) {
                    // Grab the profile data from the POST
                    $instellingnaam = mysqli_real_escape_string($dbc, trim($_POST['instellingnaam']));
                    $adres = mysqli_real_escape_string($dbc, trim($_POST['adres']));
                    $postcode = mysqli_real_escape_string($dbc, trim($_POST['postcode']));
                    $woonplaats = mysqli_real_escape_string($dbc, trim($_POST['woonplaats']));
                    $province = mysqli_real_escape_string($dbc, trim($_POST['province']));
                    $telefoon = mysqli_real_escape_string($dbc, trim($_POST['telefoon']));
                    $email = mysqli_real_escape_string($dbc, trim($_POST['email']));
                    $old_picture = mysqli_real_escape_string($dbc, trim($_POST['old_picture']));
                    $new_picture = mysqli_real_escape_string($dbc, trim($_FILES['new_picture']['name']));
                    $new_picture_type = $_FILES['new_picture']['type'];
                    $new_picture_size = $_FILES['new_picture']['size'];
                    list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']);
                    $error = false;
                    // Validate and move the uploaded picture file, if necessary
                    if (!empty($new_picture)) {
                        if ((($new_picture_type == 'image/gif') || ($new_picture_type == 'image/jpeg') || ($new_picture_type == 'image/pjpeg') ||
                                ($new_picture_type == 'image/png')) && ($new_picture_size > 0) && ($new_picture_size <= MM_MAXFILESIZE) &&
                                ($new_picture_width <= MM_MAXIMGWIDTH) && ($new_picture_height <= MM_MAXIMGHEIGHT)) {
                            if ($_FILES['new_picture']['error'] == 0) {
                                // Move the file to the target upload folder
                                $target = MM_UPLOADPATH . basename($new_picture);
                                if (move_uploaded_file($_FILES['new_picture']['tmp_name'], $target)) {
                                    // The new picture file move was successful, now make sure any old picture is deleted
                                    if (!empty($old_picture) && ($old_picture != $new_picture)) {
                                        @unlink(MM_UPLOADPATH . $old_picture);
                                    }
                                } else {
                                    // The new picture file move failed, so delete the temporary file and set the error flag
                                    @unlink($_FILES['new_picture']['tmp_name']);
                                    $error = true;
                                    echo '<p class="error">Sorry, there was a problem uploading your picture.</p>';
                                }
                            }
                        } else {
                            // The new picture file is not valid, so delete the temporary file and set the error flag
                            @unlink($_FILES['new_picture']['tmp_name']);
                            $error = true;
                            echo '<p class="error">Your picture must be a GIF, JPEG, or PNG image file no greater than ' . (MM_MAXFILESIZE / 1024) .
                            ' KB and ' . MM_MAXIMGWIDTH . 'x' . MM_MAXIMGHEIGHT . ' pixels in size.</p>';
                        }
                    }


                    // Update the profile data in the database
                    if (!$error) {
                        if (!empty($instellingnaam) && !empty($adres) && !empty($postcode) && !empty($woonplaats) && !empty($province) && !empty($telefoon) && !empty($email)) {
                            if (!empty($new_picture)) {
                                $query = "UPDATE werkgeverprofiel SET instellingnaam = '$instellingnaam', adres = '$adres', postcode = '$postcode', woonplaats = '$woonplaats', provencie = '$province', telefoon = '$telefoon', email = '$email', logo = '$new_picture' WHERE werkgeverID = '" . $_SESSION['user_id'] . "'";
                            } else {
                                $query = "UPDATE werkgeverprofiel SET instellingnaam = '$instellingnaam', adres = '$adres', postcode = '$postcode', woonplaats = '$woonplaats', provencie = '$province', telefoon = '$telefoon', email = '$email' WHERE werkgeverID = '" . $_SESSION['user_id'] . "'";
                            }
                            mysqli_query($dbc, $query);

                            $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php?p=viewprofilec';
                            header('Location: ' . $home_url);

                            mysqli_close($dbc);
                            exit();
                        } else {
                            echo '<p class="error">You must enter all of the profile data (the picture is optional).</p>';
                        }
                    }
                } // End of check for form submission
                else {
                    // Grab the profile data from the database
                    $query = "SELECT instellingnaam, adres, postcode, woonplaats, provencie, telefoon, email, logo, film FROM werkgeverprofiel WHERE werkgeverID = '" . $_SESSION['user_id'] . "'";
                    $data = mysqli_query($dbc, $query);
                    $row = mysqli_fetch_array($data);

                    if ($row != NULL) {
                        $instellingnaam = $row['instellingnaam'];
                        $adres = $row['adres'];
                        $postcode = $row['postcode'];
                        $woonplaats = $row['woonplaats'];
                        $province = $row['provencie'];
                        $telefoon = $row['telefoon'];
                        $email = $row['email'];
                        $old_picture = $row['logo'];
                        $old_film = $row['film'];
                    } else {
                        echo '<p class="error">There was a problem accessing your profile.</p>';
                    }
                }
                mysqli_close($dbc);
            } else {
                echo '<p class="login">Please <a href="../index.php?p=home">log in</a> to access this page.</p>';
                exit();
            }
            ?>
            <form enctype="multipart/form-data" method="post" action="index.php?p=editprofilec">
                <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MM_MAXFILESIZE; ?>" />
                <fieldset class="info">
                    <p class="insidetitel">Bedrijfsinformatie</p>
                    <p class="titel"> Instellingnaam</p>
                    <input name="instellingnaam" id="instellingnaam" class="edit" type="text" value="<?php if (!empty($instellingnaam))
                echo $instellingnaam; ?>"/>

                    <p class="titel">Adres</p>
                    <input name="adres" id="adres" class="edit" type="text" value="<?php if (!empty($adres))
                               echo $adres; ?>"/>

                    <p class="titel">Postcode</p>
                    <input name="postcode" id="postcode" class="edit" type="text" value="<?php if (!empty($postcode))
                               echo $postcode; ?>"/>

                    <p class="titel">Woonplaats</p>
                    <input name="woonplaats" id="woonplaats" class="edit" type="text"value="<?php if (!empty($woonplaats))
                               echo $woonplaats; ?>" />

                    <p class="titel">Provincie</p>
                    <select name="province" class="edit">
                        <option value="Groningen" <?php if (!empty($province) && $province == 'Groningen')
                               echo 'selected = "selected"'; ?>>Groningen</option>
                        <option value="Friesland" <?php if (!empty($province) && $province == 'Friesland')
                                    echo 'selected = "selected"'; ?>>Friesland</option>
                        <option value="Drenthe" <?php if (!empty($province) && $province == 'Drenthe')
                                    echo 'selected = "selected"'; ?>>Drenthe</option>
                        <option value="Overijssel" <?php if (!empty($province) && $province == 'Overijssel')
                                    echo 'selected = "selected"'; ?>>Overijssel</option>
                        <option value="Flevoland" <?php if (!empty($province) && $province == 'Flevoland')
                                    echo 'selected = "selected"'; ?>>Flevoland</option>
                        <option value="Gelderland" <?php if (!empty($province) && $province == 'Gelderland')
                                    echo 'selected = "selected"'; ?>>Gelderland</option>
                        <option value="Utrecht" <?php if (!empty($province) && $province == 'Utrecht')
                                    echo 'selected = "selected"'; ?> >Utrecht</option>
                        <option value="Noord-Holland" <?php if (!empty($province) && $province == 'Noord-Holland')
                                    echo 'selected = "selected"'; ?>>Noord-Holland</option>
                        <option value="Zuid-Holland" <?php if (!empty($province) && $province == 'Zuid-Holland')
                                    echo 'selected = "selected"'; ?>>Zuid-Holland</option>
                        <option value="Zeeland" <?php if (!empty($province) && $province == 'Zeeland')
                                    echo 'selected = "selected"'; ?>>Zeeland</option>
                        <option value="Noord-Barabant" <?php if (!empty($province) && $province == 'Noord-Barabant')
                                    echo 'selected = "selected"'; ?>>Noord-Barabant</option>
                        <option value="Limburg" <?php if (!empty($province) && $province == 'Limburg')
                                    echo 'selected = "selected"'; ?>>Limburg</option>
                    </select>

                    <p class="titel">Telefoon</p>
                    <input name="telefoon" id="telefoon" class="edit" type="text" value="<?php if (!empty($telefoon))
                                    echo $telefoon; ?>" />

                         <p class="titel">Gebruikersnaam (je email)</p>
                         <input name="email" id="email" type="text" class="edit" value="<?php if (!empty($email))
                                    echo $email; ?>"/>

                         <p class="insidetitel">Bedrijfslogo</p>
                         <p class="titel">Bedrijfslogo:</p>
                         <input type="hidden" name="old_picture" class="edit" value="<?php if (!empty($old_picture))
                                    echo $old_picture; ?>" />
                         <input type="file" id="new_picture" class="edit" name="new_picture" />
                    <?php
                                if (!empty($old_picture)) {
                                    echo '<img class="profile" src="' . MM_UPLOADPATH . $old_picture . '" alt="Profile Picture" />';
                                }
                    ?>

                                <p class="insidetitel">Bedrijfspresentatie</p>
                                <p class="titel">Film:</p>
                                <input type="hidden" name="old_film" class="edit" value="<?php if (!empty($old_film))
                                    echo $old_film; ?>" />
                         <input type="file" id="new_film" class="edit" name="new_film" />
                         <div id="film">

                        <?php
                                if (!empty($old_film)) {
                                    echo ' <OBJECT ID="MediaPlayer" WIDTH="245" HEIGHT="200" CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
            STANDBY="Loading Windows Media Player components..." TYPE="application/x-oleobject">
            <PARAM NAME="FileName" VALUE="' . MM_UPLOADPATH . $old_film . '">
            <PARAM name="autostart" VALUE="false">
            <PARAM name="ShowControls" VALUE="true">
            <param name="ShowStatusBar" value="false">
            <PARAM name="ShowDisplay" VALUE="false">
            <EMBED TYPE="application/x-mplayer2" SRC="' . MM_UPLOADPATH . $old_film . '" NAME="MediaPlayer"
            WIDTH="290" HEIGHT="290" ShowControls="1" ShowStatusBar="0" ShowDisplay="0" autostart="0"> </EMBED>
            </OBJECT>';
                                }
                        ?>
                            </div>

                        </fieldset>
                        <input type="submit" value="Save Profile" name="submit" /><br/>
                        <input type="submit" value="Delete profile" name="delete" class="deletebtn" />
                    </form>
                </div>
            </div>
    <?php
                                $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);

                                $query = "SELECT relatienummer FROM werkgeverprofiel WHERE werkgeverID = '" . $_SESSION['user_id'] . "'";
                                $data = mysqli_query($dbc, $query);
                                $row = mysqli_fetch_array($data);

                                $querystage = "SELECT stageID, stagetitel, stageplaats, stagetype, stageniveau, stageperiode, stagevergoeding, stagedatum , omschrijving FROM stages WHERE relatienummer = '" . $row['relatienummer'] . "'";
                                $datastage = mysqli_query($dbc, $querystage);
                                echo '<div id="fragment-2">';
                                echo '<div id="profile">';
                                echo '<form enctype="multipart/form-data" method="post" action="index.php?p=editprofilec">';
                                echo '<fieldset class="info">';
                                while ($rowstage = mysqli_fetch_array($datastage)) {
                                    echo '<p class="insidetitel">Stage gegevens</p>';
                                    echo '<p class="titel">Stagetitel:</p><p class="in">' . $rowstage['stagetitel'] . '</p>';
                                    echo '<p class="titel">Stageplaats:</p><p class="in">' . $rowstage['stageplaats'] . '</p>';
                                    echo '<p class="titel">Stagetype:</p><p class="in">' . $rowstage['stagetype'] . '</p>';
                                    echo '<p class="titel">Niveau:</p><p class="in">' . $rowstage['stageniveau'] . '</p>';
                                    echo '<p class="titel">Stageperiode:</p><p class="in">' . $rowstage['stageperiode'] . '</p>';
                                    echo '<p class="titel">Stagevergoeding:</p><p class="in">' . $rowstage['stagevergoeding'] . '</p>';
                                    echo '<p class="titel">Stagedatum:</p><p class="in">' . $rowstage['stagedatum'] . '</p>';
                                    echo '<p class="titel">Omschrijving:</p>';
                                    echo '<p class="omin">' . $rowstage['omschrijving'] . '</p>';
                                }

                                echo '<p class="insidetitel">New stage</p>';
                                echo '<p class="titel">Stage titel:</p>';
                                echo '<input name="stagetitel" id="stagetitel" type="text" class="edit"/>';
                                echo '<p class="titel">Stage plaats:</p>';
                                echo '<input name="stageplaats" id="stageplaats" type="text" class="edit"/>';
                                echo '<p class="titel">Stagetype:</p>';
                                echo '<select name="stagetype" class="edit">';
                                echo '<option value="Stageopdracht">Stageopdracht</option>';
                                echo '<option value="Afstudeeropdracht">Afstudeeropdracht</option>';
                                echo '</select>';
                                echo '<p class="titel">Stage niveau:</p>';
                                echo '<select name="stageniveau" class="edit">';
                                echo '<option value="MBO">MBO</option>';
                                echo '<option value="HBO">HBO</option>';
                                echo '<option value="WO">WO</option>';
                                echo '</select>';
                                echo '<p class="titel">Stageperiode</p>';
                                echo '<input name="stageperiode" id="stageperiode" type="text" class="edit"/>';
                                echo '<p class="titel">Stagevergoeding</p>';
                                echo '<input name="stagevergoeding" id="stagevergoeding" type="text" class="edit"/>';
                                echo '<p class="titel">Stagedatum:</p>';
                                echo '<input type="text" id="stagedatum" class="edit" name="stagedatum" />';
                                echo '<p class="titel">Omschrijving</p>';
                                echo '<textarea cols="" rows="" class="edit"  name="omschrijving" id="omschrijving"></textarea>';
                                echo '</fieldset>';
                                echo '<input type="submit" value="Save Profile" name="submitstage" />';
                                echo '<input type="submit" value="Delete stage" name="deleteStage" class="deletebtn" />';
                                echo '</form>';
                                echo '</div>';
                                echo '</div>';

                                $queryvacatur = "SELECT vacaturID, vacaturetitel, vacaturplaats, vacatureniveau, uren, vomschrijving FROM vacatures WHERE relatienummer = '" . $row['relatienummer'] . "'";
                                $datavacatur = mysqli_query($dbc, $queryvacatur);
                                echo '<div id="fragment-3">';
                                echo '<div id="profile">';
                                echo '<form enctype="multipart/form-data" method="post" action="index.php?p=editprofilec">';
                                echo '<fieldset class="info">';
                                while ($rowvacatur = mysqli_fetch_array($datavacatur)) {
                                    echo '<p class="insidetitel">Vacatur gegevens</p>';
                                    echo '<p class="titel">Vacaturetitel:</p><p class="in">' . $rowvacatur['vacaturetitel'] . '</p>';
                                    echo '<p class="titel">Vacaturplaats:</p><p class="in">' . $rowvacatur['vacaturplaats'] . '</p>';
                                    echo '<p class="titel">Vacatureniveau:</p><p class="in">' . $rowvacatur['vacatureniveau'] . '</p>';
                                    echo '<p class="titel">uren:</p><p class="in">' . $rowvacatur['uren'] . '</p>';
                                    echo '<p class="titel">Omschrijving:</p>';
                                    echo '<p class="omin">' . $rowvacatur['vomschrijving'] . '</p>';
                                }

                                echo '<p class="insidetitel">New vacatur</p>';
                                echo '<p class="titel">Vacatur titel:</p>';
                                echo '<input name="vacaturetitel" id="vacaturetitel" type="text" class="edit"/>';
                                echo '<p class="titel">Vacatur plaats:</p>';
                                echo '<input name="vacaturplaats" id="vacaturplaats" type="text" class="edit"/>';
                                echo '<p class="titel">Vacature niveau:</p>';
                                echo '<select name="vacatureniveau" class="edit">';
                                echo '<option value="MBO">MBO</option>';
                                echo '<option value="HBO">HBO</option>';
                                echo '<option value="WO">WO</option>';
                                echo '</select>';
                                echo '<p class="titel">uren</p>';
                                echo '<input name="uren" id="uren" type="text" class="edit"/>';
                                echo '<p class="titel">Omschrijving</p>';
                                echo '<textarea cols="" rows="" class="edit"  name="vomschrijving" id="vomschrijving"></textarea>';
                                echo '</fieldset>';
                                echo '<input type="submit" value="Save Profile" name="submitVacatures" />';
                                echo '<input type="submit" value="Delete Vacatures" name="deleteVacatures" class="deletebtn" />';
                                echo '</form>';
                                echo '</div>';
                                echo '</div>';

                                $querymedewerker = "SELECT medewerkerID, medewerkernaam, medewerkerspecialist FROM medewerkers WHERE relatienummer = '" . $row['relatienummer'] . "'";
                                $datamedewerker = mysqli_query($dbc, $querymedewerker);
                                echo '<div id="fragment-4">';
                                echo '<div id="profile">';
                                echo '<form enctype="multipart/form-data" method="post" action="index.php?p=editprofilec">';
                                echo '<fieldset class="info">';
                                while ($rowmedewerker = mysqli_fetch_array($datamedewerker)) {
                                    echo '<p class="insidetitel">Medewerker gegevens</p>';
                                    echo '<p class="titel">Medewerker naam:</p><p class="in">' . $rowmedewerker['medewerkernaam'] . '</p>';
                                    echo '<p class="titel">Specialist:</p><p class="in">' . $rowmedewerker['medewerkerspecialist'] . '</p>';
                                }

                                echo '<p class="insidetitel">New medewerker</p>';
                                echo '<p class="titel">Medewerker naam:</p>';
                                echo '<input name="medewerkernaam" id="medewerkernaam" type="text" class="edit"/>';
                                echo '<p class="titel">Specialist:</p>';
                                echo '<input name="medewerkerspecialist" id="medewerkerspecialist" type="text" class="edit"/>';
                                echo '</fieldset>';
                                echo '<input type="submit" value="Save Profile" name="submitMedewerkers" />';
                                echo '<input type="submit" value="Delete medewerkers" name="deleteMedewerkers" class="deletebtn" />';
                                echo '</form>';
                                echo '</div>';
                                echo '</div>';
    ?>
</div>
